# -*- coding: utf-8 -*-

# Define here the models for your scraped items
#
# See documentation in:
# http://doc.scrapy.org/en/latest/topics/items.html

import scrapy


class SpiderItem(scrapy.Item):
    # define the fields for your item here like:
    # name = scrapy.Field()
    pass


class TaobaoItem(scrapy.Item):
    # url_object_id = scrapy.Field()
    push_date = scrapy.Field() # 添加日期
    url = scrapy.Field()  # 链接
    current_pageNum = scrapy.Field()# 当前页
    sequence = scrapy.Field()# 第几条数据
    title = scrapy.Field() # 标题
    specie= scrapy.Field()  # 家具类型（床，桌子，椅子...）
    market_price = scrapy.Field() # 市场价
    price = scrapy.Field() # 淘宝价
    image_urls = scrapy.Field() # 存储网络图片路径的列表
    image_files = scrapy.Field() # 存储本地图片路径的列表,见CustomImagesPipeline
    evaluation_cumulative = scrapy.Field() # 累计评论数量
    evaluation_additional = scrapy.Field() # 追加评论数量
    evaluation_good = scrapy.Field() # 好评论数量
    evaluation_medium = scrapy.Field() # 中评论数量
    evaluation_poor = scrapy.Field() # 差评论数量
    storeLink = scrapy.Field() # 所属店铺链接
    storeQualification = scrapy.Field() # 店铺资质
    storeDescription = scrapy.Field() # 描述相符
    storeService = scrapy.Field() # 服务态度
    storeLogistics = scrapy.Field() # 物流服务

    def get_insert_sql_mysql(self):
        """
        :return: insert sql for mysql
        """
        sql = """
            INSERT INTO taobao(title,url,url_object_id,image_urls,image_files,push_date,market_price,taobao_price) 
            VALUES(%s,%s,%s,%s,%s,%s,%s,%s) 
            ON DUPLICATE KEY UPDATE title=VALUES(title)
        """
        if len(self["image_urls"]) == 1:
            self["image_urls"] = self["image_urls"][0]
        if len(self["image_files"]) ==1:
            self["image_files"] = self["image_files"][0]
        params = (
            self["title"],
            self["url"],
            self["url_object_id"],
            self["image_urls"],
            self["image_files"],
            self["push_date"],
            self["market_price"],
            self["taobao_price"],
        )
        return sql, params


class JinDongItem(scrapy.Item):
    url = scrapy.Field()
    title = scrapy.Field()
    # 家具类型（床，桌子，椅子...）
    type = scrapy.Field()
    # 存取网络图片路径的列表
    image_urls = scrapy.Field()
    # 本地图片保存路径的列表,见CustomImagesPipeline
    image_files = scrapy.Field()
    market_price = scrapy.Field()
    push_date = scrapy.Field()